package com.example.service.group.controller;


import com.example.common.ResponseVO;
import com.example.common.model.SyncReq;
import com.example.service.group.model.req.*;
import com.example.service.group.service.GroupMessageService;
import com.example.service.group.service.ImGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @description:
 * @author: ysh
 * @version: 1.0
 */
@RestController
@RequestMapping("v1/group")
@Api(tags = "群聊相关接口")
public class ImGroupController {

    @Autowired
    ImGroupService groupService;

    @Autowired
    GroupMessageService groupMessageService;

    @PostMapping("/importGroup")
    @ApiOperation("导入群聊")
    public ResponseVO importGroup(@RequestBody @Validated ImportGroupReq req)  {  //, Integer appId  , String identifier
//        req.setAppId(appId);
//        req.setOperater(identifier);
        return groupService.importGroup(req);
    }

    @PostMapping("/createGroup")
    @ApiOperation("创建群聊")
    public ResponseVO createGroup(@RequestBody @Validated CreateGroupReq req )  { //Integer appId //, ,String identifier
//        req.setAppId(appId);
//        req.setOperater(identifier);
        return groupService.createGroup(req);
    }

    @GetMapping("/getGroupInfo")
    @ApiOperation("获取群聊信息")
    public ResponseVO getGroupInfo(@Validated GetGroupReq req)  {// Integer appId  @RequestBody
//        req.setAppId(appId);
        return groupService.getGroup(req);
    }

    @PostMapping("/update")
    @ApiOperation("修改群聊信息")
    public ResponseVO update(@RequestBody @Validated UpdateGroupReq req)  {  //, Integer appId  , String identifier
//        req.setAppId(appId);
//        req.setOperater(identifier);
        return groupService.updateBaseGroupInfo(req);
    }

    @GetMapping("/getJoinedGroup")
    @ApiOperation("获取已加入群聊")
    public ResponseVO getJoinedGroup( @Validated GetJoinedGroupReq req)  { //, Integer appId , String identifier @RequestBody
//        req.setAppId(appId);
//        req.setOperater(identifier);
        return groupService.getJoinedGroup(req);
    }


    @PostMapping("/destroyGroup")
    @ApiOperation("解散群聊")
    public ResponseVO destroyGroup(@RequestBody @Validated DestroyGroupReq req)  { //, Integer appId  , String identifier
//        req.setAppId(appId);
//        req.setOperater(identifier);
        return groupService.destroyGroup(req);
    }

    @PostMapping("/transferGroup")
    @ApiOperation("转让群聊")
    public ResponseVO transferGroup(@RequestBody @Validated TransferGroupReq req )  { //Integer appId  , String identifier
//        req.setAppId(appId);
//        req.setOperater(identifier);
        return groupService.transferGroup(req);
    }

    @PostMapping("/forbidSendMessage")
    @ApiOperation("改变发言的状态（是禁言还是不禁言）")
    public ResponseVO forbidSendMessage(@RequestBody @Validated MuteGroupReq req)  { //, Integer appId  , String identifier
//        req.setAppId(appId);
//        req.setOperater(identifier);
        return groupService.muteGroup(req);
    }

    @PostMapping("/sendMessage")
    @ApiOperation("群聊消息的发送")
    public ResponseVO sendMessage(@RequestBody @Validated SendGroupMessageReq
                                          req)  {
//        req.setAppId(appId);
//        req.setOperater(identifier);
        return ResponseVO.successResponse(groupMessageService.send(req));
    }

    @PostMapping("/syncJoinedGroup")
    @ApiOperation("群聊的增量同步")
    public ResponseVO syncJoinedGroup(@RequestBody @Validated SyncReq req)  {
        return groupService.syncJoinedGroupList(req);
    }

}
